<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function sl(num){
      if(!num)return;
      if(isNaN(Number(num)))return;
      let arr = [];
      let str = num.toString();
      main(str);
      function main(str){
        arr[arr.length] = str.slice(-3);
        let last = str.slice(0,-3)
        if(last.length > 3){
          main(last);
        } else {
          arr[arr.length] = last;
        }
      }
      return arr.reverse().join(',');
    }

    let num = sl(10000000);
    console.log(num);
  </script>
</body>
</html>